'/
' Fetherquest Online
' 
' =========================================================================
' 
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
' 
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
' 
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>.
'/

include "../../framework/network/netcodes.bmx"
include "BasePeer.bmx"
include "ServerPeer.bmx"
include "MasterPeer.bmx"

type NetworkManager extends Base

	'// -------------------------------------------------------------------------------------------------------------
	'// Initialize the network peers.
	'// -------------------------------------------------------------------------------------------------------------
	method init()
	
		m_masterPeer = new MasterPeer;
		m_serverPeer = new ServerPeer;
		
		m_peerList.addLast(m_masterPeer);
		m_peerList.addLast(m_serverPeer);
		
		for local peer:BasePeer = eachin m_peerList
		
			peer.init();
		
		next
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// Deinitialize the network peers.
	'// -------------------------------------------------------------------------------------------------------------
	method deinit()
	
		for local peer:BasePeer = eachin m_peerList
		
			peer.deinit();
		
		next
	
	end method
	
	'// -----------------------------------------------------------------------------------------------------------------
	'// Update the netcode.
	'// -----------------------------------------------------------------------------------------------------------------
	method update()
	
		for local peer:BasePeer = eachin m_peerList
		
			if (peer.m_connected) ..
				peer.update();
		
		next
	
	end method
	
	'// -------------------------------------------------------------------------------------------------------------
	'// List of network peers, one for each connection.
	'// -------------------------------------------------------------------------------------------------------------
	field m_peerList:TList = new TList;
	
	'// -------------------------------------------------------------------------------------------------------------
	'// 
	'// -------------------------------------------------------------------------------------------------------------
	field m_masterPeer:MasterPeer = null;

	'// -------------------------------------------------------------------------------------------------------------
	'// 
	'// -------------------------------------------------------------------------------------------------------------
	field m_serverPeer:ServerPeer = null;

end type

global sNetworkManager:NetworkManager = new NetworkManager;
